﻿using System.Linq;
using Enyim.Caching;
using Ayatta.Contract;
using System.Web.Mvc;
using Web.Base.Security;
using Web.Game.Models;
using Ayatta.Contract.Extension;

namespace Web.Game.Controllers
{
    public class PlayController : GameBaseController
    {
        public PlayController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient)
            : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        public ActionResult Index()
        {
            return Redirect("/");
        }

        /// <summary>
        /// 游戏入口
        /// </summary>
        /// <param name="param">服Id</param>
        /// <returns></returns>
        public ActionResult Gateway(int param)
        {
            var games = GetGames();
            var identity = User.Identity.Identity();
            var servers = games.GetAllServers();
            var model = new PlayControllerModel.Gateway();
            var server = servers.FirstOrDefault(o => o.Id == param);

            if (server != null)
            {
                var game = games.FirstOrDefault(o => o.Id == server.Id);
                if (game != null)
                {
                    model.Game = game;
                    model.LoginUrl = GetLoginUri(game.Id, identity.Guid, "358080001");
                }
            }
            return View(model);
        }
    }
}
